home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JDBC / JDBC_011 / JAVA / SQL / PREPARED.JAV < prev    next >
Encoding:
Text File  |  1996-11-10  |  12.7 KB  |  325 lines

  1. /*
  2.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "LICENSE"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  * 
  17.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  18.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  19.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  20.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  21.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  22.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  23.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  24.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  25.  * HIGH RISK ACTIVITIES.
  26.  */
  27.  
  28. package java.sql;
  29.  
  30. /**
  31.  * <P>A SQL statement is pre-compiled and stored in a
  32.  * PreparedStatement object. This object can then be used to
  33.  * efficiently execute this statement multiple times. 
  34.  *
  35.  * <P><B>Note:</B> The setXXX methods for setting IN parameter values
  36.  * must specify types that are compatible with the defined SQL type of
  37.  * the input parameter. For instance, if the IN parameter has SQL type
  38.  * Integer then setInt should be used.
  39.  *
  40.  * <p>If arbitrary parameter type conversions are required then the
  41.  * setObject method should be used with a target SQL type.
  42.  *
  43.  * @see Connection#prepareStatement
  44.  * @see ResultSet 
  45.  */
  46.  
  47. public interface PreparedStatement extends Statement {
  48.  
  49.     /**
  50.      * A prepared SQL query is executed and its ResultSet is returned.
  51.      *
  52.      * @return a ResultSet that contains the data produced by the
  53.      * query; never null
  54.      */
  55.     ResultSet executeQuery() throws SQLException;
  56.  
  57.     /**
  58.      * Execute a SQL INSERT, UPDATE or DELETE statement. In addition,
  59.      * SQL statements that return nothing such as SQL DDL statements
  60.      * can be executed.
  61.      *
  62.      * @return either the row count for INSERT, UPDATE or DELETE; or 0
  63.      * for SQL statements that return nothing
  64.      */
  65.     int executeUpdate() throws SQLException;
  66.  
  67.     /**
  68.      * Set a parameter to SQL NULL.
  69.      *
  70.      * <P><B>Note:</B> You must specify the parameter's SQL type.
  71.      *
  72.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  73.      * @param sqlType SQL type code defined by java.sql.Types
  74.      */
  75.     void setNull(int parameterIndex, int sqlType) throws SQLException;
  76.  
  77.     /**
  78.      * Set a parameter to a Java boolean value.  The driver converts this
  79.      * to a SQL BIT value when it sends it to the database.
  80.      *
  81.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  82.      * @param x the parameter value
  83.      */
  84.     void setBoolean(int parameterIndex, boolean x) throws SQLException;
  85.  
  86.     /**
  87.      * Set a parameter to a Java byte value.  The driver converts this
  88.      * to a SQL TINYINT value when it sends it to the database.
  89.      *
  90.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  91.      * @param x the parameter value
  92.      */
  93.     void setByte(int parameterIndex, byte x) throws SQLException;
  94.  
  95.     /**
  96.      * Set a parameter to a Java short value.  The driver converts this
  97.      * to a SQL SMALLINT value when it sends it to the database.
  98.      *
  99.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  100.      * @param x the parameter value
  101.      */
  102.     void setShort(int parameterIndex, short x) throws SQLException;
  103.  
  104.     /**
  105.      * Set a parameter to a Java int value.  The driver converts this
  106.      * to a SQL INTEGER value when it sends it to the database.
  107.      *
  108.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  109.      * @param x the parameter value
  110.      */
  111.     void setInt(int parameterIndex, int x) throws SQLException;
  112.  
  113.     /**
  114.      * Set a parameter to a Java long value.  The driver converts this
  115.      * to a SQL BIGINT value when it sends it to the database.
  116.      *
  117.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  118.      * @param x the parameter value
  119.      */
  120.     void setLong(int parameterIndex, long x) throws SQLException;
  121.  
  122.     /**
  123.      * Set a parameter to a Java float value.  The driver converts this
  124.      * to a SQL FLOAT value when it sends it to the database.
  125.      *
  126.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  127.      * @param x the parameter value
  128.      */
  129.     void setFloat(int parameterIndex, float x) throws SQLException;
  130.  
  131.     /**
  132.      * Set a parameter to a Java double value.  The driver converts this
  133.      * to a SQL DOUBLE value when it sends it to the database.
  134.      *
  135.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  136.      * @param x the parameter value
  137.      */
  138.     void setDouble(int parameterIndex, double x) throws SQLException;
  139.  
  140.     /**
  141.      * Set a parameter to a java.lang.Bignum value.  The driver converts this
  142.      * to a SQL NUMERIC value when it sends it to the database.
  143.      *
  144.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  145.      * @param x the parameter value
  146.      */
  147.     void setBignum(int parameterIndex, Bignum x) throws SQLException;
  148.  
  149.     /**
  150.      * Set a parameter to a Java String value.  The driver converts this
  151.      * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments
  152.      * size relative to the driver's limits on VARCHARs) when it sends
  153.      * it to the database.
  154.      *
  155.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  156.      * @param x the parameter value
  157.      */
  158.     void setString(int parameterIndex, String x) throws SQLException;
  159.  
  160.     /**
  161.      * Set a parameter to a Java array of bytes.  The driver converts
  162.      * this to a SQL VARBINARY or LONGVARBINARY (depending on the
  163.      * argument's size relative to the driver's limits on VARBINARYs)
  164.      * when it sends it to the database.
  165.      *
  166.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  167.      * @param x the parameter value 
  168.      */
  169.     void setBytes(int parameterIndex, byte x[]) throws SQLException;
  170.  
  171.     /**
  172.      * Set a parameter to a java.sql.Date value.  The driver converts this
  173.      * to a SQL DATE value when it sends it to the database.
  174.      *
  175.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  176.      * @param x the parameter value
  177.      */
  178.     void setDate(int parameterIndex, java.sql.Date x)
  179.         throws SQLException;
  180.  
  181.     /**
  182.      * Set a parameter to a java.sql.Time value.  The driver converts this
  183.      * to a SQL TIME value when it sends it to the database.
  184.      *
  185.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  186.      * @param x the parameter value
  187.      */
  188.     void setTime(int parameterIndex, java.sql.Time x) 
  189.         throws SQLException;
  190.  
  191.     /**
  192.      * Set a parameter to a java.sql.Timestamp value.  The driver
  193.      * converts this to a SQL TIMESTAMP value when it sends it to the
  194.      * database.
  195.      *
  196.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  197.      * @param x the parameter value 
  198.      */
  199.     void setTimestamp(int parameterIndex, java.sql.Timestamp x)
  200.         throws SQLException;
  201.  
  202.     /**
  203.      * When a very large ASCII value is input to a LONGVARCHAR
  204.      * parameter, it may be more practical to send it via a
  205.      * java.io.InputStream. JDBC will read the data from the stream
  206.      * as needed, until it reaches end-of-file.  The JDBC driver will
  207.      * do any necessary conversion from ASCII to the database char format.
  208.      * 
  209.      * <P><B>Note:</B> This stream object can either be a standard
  210.      * Java stream object or your own subclass that implements the
  211.      * standard interface.
  212.      *
  213.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  214.      * @param x the java input stream which contains the ASCII parameter value
  215.      * @param length the number of bytes in the stream 
  216.      */
  217.     void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
  218.         throws SQLException;
  219.  
  220.     /**
  221.      * When a very large UNICODE value is input to a LONGVARCHAR
  222.      * parameter, it may be more practical to send it via a
  223.      * java.io.InputStream. JDBC will read the data from the stream
  224.      * as needed, until it reaches end-of-file.  The JDBC driver will
  225.      * do any necessary conversion from UNICODE to the database char format.
  226.      * 
  227.      * <P><B>Note:</B> This stream object can either be a standard
  228.      * Java stream object or your own subclass that implements the
  229.      * standard interface.
  230.      *
  231.      * @param parameterIndex the first parameter is 1, the second is 2, ...  
  232.      * @param x the java input stream which contains the
  233.      * UNICODE parameter value 
  234.      * @param length the number of bytes in the stream 
  235.      */
  236.     void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length)
  237.         throws SQLException;
  238.  
  239.     /**
  240.      * When a very large binary value is input to a LONGVARBINARY
  241.      * parameter, it may be more practical to send it via a
  242.      * java.io.InputStream. JDBC will read the data from the stream
  243.      * as needed, until it reaches end-of-file.
  244.      * 
  245.      * <P><B>Note:</B> This stream object can either be a standard
  246.      * Java stream object or your own subclass that implements the
  247.      * standard interface.
  248.      *
  249.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  250.      * @param x the java input stream which contains the binary parameter value
  251.      * @param length the number of bytes in the stream 
  252.      */
  253.     void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) 
  254.         throws SQLException;
  255.  
  256.     /**
  257.      * <P>In general, parameter values remain in force for repeated use of a
  258.      * Statement. Setting a parameter value automatically clears its
  259.      * previous value.  However, in some cases it is useful to immediately
  260.      * release the resources used by the current parameter values; this can
  261.      * be done by calling clearParameters.
  262.      */
  263.     void clearParameters() throws SQLException;
  264.  
  265.     //----------------------------------------------------------------------
  266.     // Advanced features:
  267.  
  268.     /**
  269.      * <p>Set the value of a parameter using an object; use the
  270.      * java.lang equivalent objects for integral values.
  271.      *
  272.      * <p>The given Java object will be converted to the targetSqlType
  273.      * before being sent to the database.
  274.      *
  275.      * <p>Note that this method may be used to pass datatabase-
  276.      * specific abstract data types. This is done by using a Driver-
  277.      * specific Java type and using a targetSqlType of
  278.      * java.sql.types.OTHER.
  279.      *
  280.      * @param parameterIndex The first parameter is 1, the second is 2, ...
  281.      * @param x The object containing the input parameter value
  282.      * @param targetSqlType The SQL type (as defined in java.sql.Types) to be 
  283.      * sent to the database. The scale argument may further qualify this type.
  284.      * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
  285.      *          this is the number of digits after the decimal.  For all other
  286.      *          types this value will be ignored,
  287.      * @see Types 
  288.      */
  289.     void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
  290.             throws SQLException;
  291.  
  292.     /**
  293.       * This method is like setObject above, but assumes a scale of zero.
  294.       */
  295.     void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException;
  296.  
  297.     /**
  298.      * <p>Set the value of a parameter using an object; use the
  299.      * java.lang equivalent objects for integral values.
  300.      *
  301.      * <p>The JDBC specification specifies a standard mapping from
  302.      * Java Object types to SQL types.  The given argument java object
  303.      * will be converted to the corresponding SQL type before being
  304.      * sent to the database.
  305.      *
  306.      * <p>Note that this method may be used to pass datatabase
  307.      * specific abstract data types, by using a Driver specific Java
  308.      * type.
  309.      *
  310.      * @param parameterIndex The first parameter is 1, the second is 2, ...
  311.      * @param x The object containing the input parameter value 
  312.      */
  313.     void setObject(int parameterIndex, Object x) throws SQLException;
  314.  
  315.     /**
  316.      * Some prepared statements return multiple results; the execute
  317.      * method handles these complex statements as well as the simpler
  318.      * form of statements handled by executeQuery and executeUpdate.
  319.      *
  320.      * @see Statement#execute
  321.      */
  322.     boolean execute() throws SQLException;
  323.  
  324. }
  325.